<template>
    <div >

    </div>
</template>

<script>
export default {
    data: function() {
        return {
            state:"",
            code:"",
        }
    },
    mounted:function () {
        debugger
        this.code = this.getQueryString('code');
        this.state = this.getQueryString('state');
        this.getToken();
    },
    methods: {
        getQueryString:function(name){
            let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            let r = window.location.search.substr(1).match(reg);
            if(r != null) {
                return decodeURIComponent(r[2]);
            }
            return '';
        },
        getToken() {
            // 传递head
            let data = {code:this.code,state:this.state,grant_type:'authorization_code',redirect_uri:this.$config.redirect_uri}
            let str = this.$querystring.stringify(data);
            this.$axios({
                url: this.$config.userTokenUri,
                method: "post",
                params: data,
                headers: {"Content-Type":"application/x-www-form-urlencoded"},
                auth: {
                    username: this.$config.clientId,
                    password: this.$config.client_secret
                }
            }).then(res => {
                console.log(res)
                localStorage.setItem('token', res.data.access_token);
                localStorage.setItem('ms_username', res.data.access_token);
                /*localStorage.setItem('token', res.data.access_token);
                localStorage.setItem('userId', res.userId);
                localStorage.setItem('headLogo', res.headLogo);
                // Cookies.set('token', res.msg)
                localStorage.setItem('ms_username', this.param.username);*/
                // 清除掉参数
                //this.$router.push({path:'/'});
                window.location.href = this.$config.index_uri;
                //this.$router.push({ query: {} });
            })
        },
    },
};
</script>

<style scoped>
.login-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    background-image: url(../../assets/img/login-bg.jpg);
    background-size: 100%;
}
.ms-title {
    width: 100%;
    line-height: 50px;
    text-align: center;
    font-size: 20px;
    color: #fff;
    border-bottom: 1px solid #ddd;
}
.ms-login {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 350px;
    margin: -190px 0 0 -175px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.3);
    overflow: hidden;
}
.ms-content {
    padding: 30px 30px;
}
.login-btn {
    text-align: center;
}
.login-btn button {
    width: 100%;
    height: 36px;
    margin-bottom: 10px;
}
.login-tips {
    font-size: 12px;
    line-height: 30px;
    color: #fff;
}
</style>